# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Shane Stone <shanewstone at gmail>

_name=pdftotext
pkgname=python-pdftotext
pkgver=2.2.2
pkgrel=4
pkgdesc='Simple PDF text extraction'
arch=('loong64' 'x86_64')
url=https://github.com/jalan/pdftotext
license=('MIT')
depends=('poppler' 'python')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz")
sha256sums=('2a9aa89bc62022408781b39d188fabf5a3ad1103b6630f32c4e27e395f7966ee')
b2sums=('5ab471cfbccd50d6b9f16e083e2b059c3fedd8eee57988a10516e9ca42dcec7743741ec4d7fd1d00e81efcce58880c9e2b2cc9cb1b9c760cfbbe98ce6cd4f1b9')

build() {
  cd $_name-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $_name-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m unittest discover
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_name-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
